<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/_fragments :: head(~{::title})">
    <title th:text="*{id}==null ? '新增博文分类' : '修改博文分类'">新增博文分类</title>
</head>
<body>
    <!--导航-->
    <nav th:replace="admin/_fragments :: menu(3)">
    </nav>
    <!--二级导航-->
    <div class="ui attached inverted pointing menu">
        <div class="ui container">
            <div class="left menu">
                <i class="add black circle icon"></i><div class="active teal item" th:text="*{id}==null ? '新增分类' : '修改分类'">新增分类</div>
                <a th:href="@{/admin/types}" class="item">分类列表</a>
            </div>
        </div>
    </div>
    <!--中间部分-->
    <div class="m-container m-padded-tb-large">
        <div class="ui container">
            <form class="ui form" method="post" th:object="${type}" th:action="*{id}==null ? @{/admin/types} : @{/admin/types/{id}(id=*{id})}">
                <div class="required field">
                    <div class="ui left labeled input">
                        <label class="ui yellow basic label"><i class=" sitemap icon"></i>分类名称</label>
                        <input type="text" th:value="*{name}" name="name" placeholder="请输入分类名称......">
                        <input type="hidden" name="id" th:value="*{id}">
                    </div>
                </div>
                <!--前端验证-->
                <div class="ui error message"></div>
                <!--后端验证-->
                <!--/*/
                <div class="ui negative message" th:if="${#fields.hasErrors('name')}">
                    <i class="class close icon"></i>
                    <div class="header">提示：</div>
                    <p th:errors="*{name}">验证失败</p>
                </div>
                /*/-->
                <div class="ui right aligned container">
                    <button class="ui button" type="button" onclick="window.history.go(-1)">返回</button>
                    <button class="ui green submit button" th:text="*{id}==null ? '新增' : '更新'">新增</button>
                </div>
            </form>
        </div>
    </div>
    </div>

    <!--底部footer-->
    <!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
    <script src="../static/js/jquery-3.6.0.min.js" th:src="@{/js/jquery-3.6.0.min.js}"></script>
    <script src="../static/js/semantic.min.js" th:src="@{/js/semantic.min.js}"></script>
    <script src="../../static/lib/editormd/editormd.js"></script>
    <!--/*/</th:block>/*/-->
<script>

    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
        return false;
    });
    $('.ui.dropdown').dropdown({
        on : 'hover'
    });
    $('.ui.form').form({
       fields : {
           title : {
               identifier : 'name',
               rules : [{
                   type : 'empty',
                   prompt : '博文分类不能为空，请输入博文分类'
               }]
           },
       },
        inline : true,
        on     : 'blur'
    });
    //消息提示关闭初始化
    $('.message .close').
    click(function () {
        $(this).
        closest('.message').
        transition('fly');
    });
</script>
</body>
</html>